<template>
	<view class="container">
		<view class="wrapper">
			<view style="background-color: rgba(255, 255, 255, 55%);padding: 40rpx 50rpx 40rpx 50rpx;border-radius: 20rpx;">
				<view style="padding: 20rpx 0rpx 50rpx 0rpx;font-size: 40rpx;text-align: center; ">
					欢迎来到全民运动健康
					<view style="line-height: 60rpx;">商户端</view>
				</view>
				<view>
					<view>
						<view style="border-radius: 8rpx;display: flex;border: 1px solid rgb(195 195 195);justify-content: center;align-items: center; ">
							<view style="padding:0px 20rpx;text-align: center;font-size: 32rpx;"><u-icon name="account-fill" size="50"></u-icon></view>
							<input style="height: 90rpx;width: 100%;font-size: 32rpx;" placeholder="输入登录账号" v-model="form.username" />
						</view>
					</view>
					<view style="height: 30rpx;"></view>
					<view >
						<view style="border-radius: 8rpx;display: flex;border: 1px solid rgb(195 195 195);justify-content: center;align-items: center; ">
							<view style="padding:0px 20rpx;text-align: center;font-size: 32rpx;"><u-icon name="lock-fill" size="50"></u-icon></view>
							<input type="password" style="height: 90rpx;border-radius: 8rpx;width: 100%;font-size: 32rpx;" placeholder="输入登录账号"  v-model="form.password"  />
						</view>
					</view>
				</view>
				<view style="height: 30rpx;"></view>
				<view>
					<button style="height: 90rpx;background-color: #0544ab;color: #ffffff;line-height: 90rpx;font-size: 32rpx;" @click="loginSubmit">登 录</button>
				</view>
				<view style="height: 50rpx;"></view>
				<view style="height: 30rpx;display: flex;">
					<view style="width: 50%;text-align: left;font-size: 30rpx;color: #333;" @click="onLink('/pages/apply/regiest/regiest')">新用户注册</view>
					<view style="width: 50%;text-align: right;font-size: 30rpx;color: #333;" @click="onLink('/pages/apply/forgetPass/forgetPass')">忘记密码</view>
				</view>
			</view>
		</view>
		
	</view>
	
</template>

<script>
	import md5 from '@/utils/md5.js';
	export default {
		data() {
			return {
				form: {
					username: '',
					password: ''
				}
			}
		},
		methods: {
			onLink(url) {
				uni.navigateTo({ url: url })
			},
			loginSubmit(){
				if(!this.form.username){
					uni.$u.toast("请输入登录账号")
					return ;
				}
				if(!this.form.password){
					uni.$u.toast("请输入登录密码")
					return ;
				}
				uni.showLoading({
					title: '登录中',
					mask: true
				})
				this.$request({
					url: `/blade-auth/oauth/token?tenantId=000000&username=${this.form.username}&password=${md5.hex_md5_32(this.form.password)}&grant_type=password&scope=all&type=account`,
					type: 'POST'
				}).then(res => {
					uni.hideLoading();
					uni.setStorageSync('avatar', res.avatar);
					uni.setStorageSync('account', res.account);
					uni.setStorageSync('nickName', res.nick_name);
					uni.setStorageSync('token', res.access_token);
					uni.setStorageSync('tokenType', res.token_type);
					uni.setStorageSync('userId', res.user_id);
					//身份（1：普通用户，2：场馆主，3：教练员，4：指导员，5：体检中心,7场馆主商家）
					uni.setStorageSync('identity', res.identity);
					if(res.identity == 7){
						//为获取商家下场馆列表的token
						uni.setStorageSync('venueToken', res.access_token);
						uni.setStorageSync('venueTokenType', res.token_type);
						uni.setStorageSync('venueIdentity', res.identity);
						uni.redirectTo({ url:'/pages/index/venueBusiness' })
					} else {
						uni.setStorageSync('venueIdentity', res.identity);
						uni.redirectTo({ url:'/pages/index/index' })
					}
				})
			}
		}
	}
	
	
</script>

<style lang="scss">
	page {
		height: 100%;
		background: #ffffff;
		overflow: hidden;
		background: linear-gradient(#155CCF,#e5e5e5, #e5e5e5);
		letter-spacing: 1rpx;

		.container {
			height: 100%;
			display: flex;
			-webkit-box-pack: center;
			justify-content: center;
			align-items: center;

			.wrapper {
				width: 85%;
			}
		}
	}			
	
</style>